#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
map<ll,ll> mp;
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    ll t;
    scanf("%lld",&t);
    while(t--){
        mp.clear();
        ll n,num,ans=0;
        scanf("%lld",&n);
        for(ll i=1;i<=n;i++){
            scanf("%lld",&num);
            mp[num]++;
        }
        map<ll,ll> ::iterator it;
        for(it=mp.begin();it!=mp.end();it++){
            ans=ans+it->first*(it->second-1);
        }
        printf("%lld\n",ans);
    }
    return 0;
}
